package days46.title349;

import java.util.HashSet;

class Solution {
    public int[] intersection(int[] nums1, int[] nums2) {
        HashSet<Integer> integers1 = new HashSet<>();
        HashSet<Integer> integers2 = new HashSet<>();
        for (int i : nums1) {
            integers1.add(i);
        }
        for (int i : nums2) {
            if (integers1.contains(i)) {
                integers2.add(i);
            }
        }
        int[] result = new int[integers2.size()];
        return integers2.stream().mapToInt(i -> i).toArray();
    }
}